package com.lkm.app_ui.jz.net;

import com.lkm.app_ui.RunTimeData;
import com.lkm.app_ui.jz.bean.JuHePayResultBean;
import com.lkm.app_ui.jz.util.JzUtil;
import com.lkm.app_ui.jz.util.SPUtils;
import com.lkm.app_ui.jz.util.Urls;
import com.lkm.frame.task.StopAble;
import com.lkm.market2_0.help.SteelardHelp;
import com.lkm.market2_0.m.steelyarddata.OrderEntity;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

import java.util.Collections;
import java.util.HashMap;

public class PayApi {
    public static final int    PAY_TYPE_JU_HE   = 2;
    public static final int    PAY_TYPE_CASH    = 1;
    public static final int    PAY_TYPE_DEFAULT = PAY_TYPE_CASH;
    public static final String PAY_TYPE         = "PAY_TYPE";

    public static void getPayInfoFromSah() {
//        String                  scaleSn = RunTimeData.steelyardInfo.getSteelyardMac();
//        HashMap<String, String> map     = new HashMap<>();
//        map.put("scale_sn", scaleSn);
//        HashMap<String, String> params = new HashMap<>();
//        params.put("act", "is_code_pay");
//        params.put("json", JzUtil.mGson.toJson(map));
//        OkGo.<String>post(Urls.getHost())
//                .params(params)
//                .execute(new StringCallback() {
//                    @Override
//                    public void onSuccess(Response<String> response) {
//                        try {
//                            JuHePayResultBean juHePayResultBean = JzUtil.mGson.fromJson(response.body(), JuHePayResultBean.class);
//                            if (null != juHePayResultBean && null != juHePayResultBean.data) {
//                                SPUtils.putInt(PAY_TYPE, juHePayResultBean.data.pay_type);
//                            } else {
//                                SPUtils.putInt(PAY_TYPE, PAY_TYPE_DEFAULT);
//                            }
//                        } catch (Exception exception) {
//                            SPUtils.putInt(PAY_TYPE, PAY_TYPE_DEFAULT);
//                        }
//                    }
//
//                    @Override
//                    public void onError(Response<String> response) {
//                        SPUtils.putInt(PAY_TYPE, PAY_TYPE_DEFAULT);
//                    }
//                });
    }

    public static void getVipPayUrl(StringCallback callback) {
        HashMap<String, String> params = new HashMap<>();
        params.put("act", "server_get_pay");
        params.put("oid", "" + RunTimeData.steelyardInfo.getOrg());
        params.put("ukey", RunTimeData.orderEntity.steelyardMac);
        params.put("od", RunTimeData.orderEntity.orderNum);
        params.put("pay", "" + RunTimeData.tmpPayType);
        params.put("amount", "" + SteelardHelp.formatMoney(RunTimeData.orderEntity.totalPrice));
        params.put("pay_code", "");
        params.put("json", JzUtil.mGson.toJson(Collections.singletonList(RunTimeData.orderEntity)));
        OkGo.<String>post(Urls.getHost())
                .params(params)
                .execute(callback);
    }

    public static void getVipPayStatus(StringCallback callback) {
        HashMap<String, String> params = new HashMap<>();
        params.put("act", "server_get_pay");
        params.put("oid", "" + RunTimeData.steelyardInfo.getOrg());
        params.put("ukey", RunTimeData.orderEntity.steelyardMac);
        params.put("od", RunTimeData.orderEntity.orderNum);
        params.put("pay", "" + RunTimeData.tmpPayType);
        params.put("amount", "" + RunTimeData.orderEntity.totalPrice);
        params.put("pay_code", "");
        params.put("json", JzUtil.mGson.toJson(Collections.singletonList(RunTimeData.orderEntity)));
        OkGo.<String>post(Urls.getHost())
                .params(params)
                .execute(callback);
    }
}
